package com.king.pojo.entity;

import lombok.Data;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.Where;
import org.springframework.data.annotation.CreatedBy;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedBy;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import org.springframework.format.annotation.DateTimeFormat;

import javax.persistence.EntityListeners;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.MappedSuperclass;
import java.time.LocalDateTime;

/**
 * @author liukai
 */
@Data
@DynamicInsert
@DynamicUpdate
@MappedSuperclass
@Where(clause = "deleted = 0")
@EntityListeners(AuditingEntityListener.class)
class BasicEntity {

    /**
     * 创建用户
     */
    @CreatedBy
    @ManyToOne
    @JoinColumn(name = "create_by")
    private SysUser createBy;

    /**
     * 修改用户
     */
    @LastModifiedBy
    @ManyToOne
    @JoinColumn(name = "update_by")
    private SysUser updateBy;

    /**
     * 创建时间
     */
    @CreatedDate
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime createTime;

    /**
     * 修改时间
     */
    @LastModifiedDate
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime updateTime;

    /**
     * 删除状态 0表示未删除 1表示已删除
     */
    private Integer deleted;

}
